<template>
  <el-card class="box-card" style="width: 1180px">   
    <div slot="header" class="clearfix">
      <el-form :inline="true" :model="query">
        <el-form-item>
          <el-row>
          <el-col :span="20">
                    <el-button type="success">合同详情</el-button>
           </el-col>
     </el-row>   
        </el-form-item>
      </el-form>
    </div>      
    <el-table :data="pipeList" border style="width: 100%">
        <el-table-column prop="id" label="合同号" >
</el-table-column>
      <el-table-column prop="diName" label="姓名" >
      </el-table-column>
      <el-table-column prop="diTel" label="电话"></el-table-column>
      <el-table-column prop="liLoanMoney" label="放款金额">
      </el-table-column>
      <el-table-column prop="diTimeLimit" label="放款期数">
      </el-table-column>
      <el-table-column prop="productName" label="产品名称">
      </el-table-column>
      <el-table-column prop="averageName" label="还款方式">
      </el-table-column>
      <el-table-column prop="allInRate" label="综合利率">
      </el-table-column>
      <el-table-column prop="diType" label="状态">
      </el-table-column>
      <el-table-column label="操作" width="220">
        <template slot-scope="scope">
          <el-button size="mini" @click="edit(scope.row.id)"
            >合同详情</el-button
          >

        </template>
      </el-table-column>
    </el-table>
    <el-dialog title="合同详情" :visible.sync="dialog.updateshow" width="30%">
      <el-form ref="updateForm" :model="updateForm" label-width="80px">
        <el-row>
          <el-col :span="24">
            <el-form-item label="合同号" prop="id">
              <el-input v-model="updateForm.id"></el-input>
            </el-form-item>
            <el-form-item label="姓名" prop="diName">
              <el-input v-model="updateForm.diName"></el-input>
            </el-form-item>
            <el-form-item label="电话" prop="diTel">
              <el-input v-model="updateForm.diTel"></el-input>
            </el-form-item>
            <el-form-item label="身份证号" prop="userIdCard">
              <el-input v-model="updateForm.userIdCard"></el-input>
            </el-form-item>
            <el-form-item label="银行名称" prop="receivingBankBranch">
              <el-input v-model="updateForm.receivingBankBranch"></el-input>
            </el-form-item>
            <el-form-item label="银行账户" prop="receivingBankNumber">
              <el-input v-model="updateForm.receivingBankNumber"></el-input>
            </el-form-item>
            <el-form-item label="总期数" prop="diTimeLimit">
              <el-input v-model="updateForm.diTimeLimit"></el-input>
            </el-form-item>
            <el-form-item label="放款金额" prop="liLoanMoney">
              <el-input v-model="updateForm.liLoanMoney"></el-input>
            </el-form-item>
            <el-form-item label="综合利息" prop="allInRate">
              <el-input v-model="updateForm.allInRate"></el-input>
            </el-form-item>
            <el-form-item label="产品名称" prop="productName">
              <el-input v-model="updateForm.productName"></el-input>
            </el-form-item>
            <el-form-item label="还款方式" prop="averageName">
              <el-input v-model="updateForm.averageName"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialog.updateshow = false">取 消</el-button>
        <el-button type="primary" @click="update()">确 定</el-button>
      </span>
    </el-dialog>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="query.currentPage"
      :page-sizes="pageInfo.pageSizes"
      :page-size="query.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="pageInfo.total">
    </el-pagination>
  </el-card>
</template>

<script>
export default {
  data() {
    return {
        dialog:{updateshow:false},
        user:{},
        pipeList:[],
        pageInfo: {       
        pageSizes: [5, 20, 30, 50, 100],        
        total: 1,
      },
      query:{
        currentPage: 1,
        pageSize: 5,
        realName:"",
        dateRange:[]
      },
      addForm:{},
      updateForm:{},
      weiDaVo:{
        diNumber:"",
        diDebitStatus:""
      }
    };
  },
  methods: {
    edit(id){
        this.$axios.get("/contracts/he/"+id)
        .then(res=>{
            if(res.data.code==200){
                this.updateForm=res.data.data.hetong;
                this.dialog.updateshow=true;
            }
        })
    },
    update(){
        this.weiDaVo.diNumber=this.updateForm.id;
        this.weiDaVo.diDebitStatus="放款审批";
        this.$axios.post("/contracts/gai",this.weiDaVo)
        .then(res=>{
            if(res.data.code==200){
                this.$message.success("确认合同成功,稍后进行打款");
                this.loadPis();
            }
        })
        this.dialog.updateshow=false;
    },
    handleSizeChange(size) {      
      this.query.pageSize = size;
      this.loadPis();
    },
    //当页数改变时
    handleCurrentChange(currentPage) {     
      this.query.currentPage = currentPage;
      this.loadPis();
    },
    loadPis(){
        this.user=JSON.parse(sessionStorage.getItem("user"));
        this.query.realName=this.user.userName;
        this.$axios.post("/contracts/heall",this.query)
        .then(res=>{
            this.pipeList=res.data.data.list;
            this.pageInfo.total=res.data.data.total;
        })
    },
  },
  mounted(){
    this.loadPis();
  }
};
</script>